1. What is the purpose of a loop in programming?
Correct Answer: B) To execute a set of instructions multiple times
2. Which of the following loops is a pre-tested loop?
Correct Answer: D) Both A and B
3. What is the correct syntax for a for loop in C?
Correct Answer: B) for(initialization; condition; increment/decrement)
4. What happens when the condition in a while loop becomes false?
Correct Answer: B) The loop terminates
5. In a do-while loop, when is the condition checked?
Correct Answer: B) After the loop executes
6. What happens if the loop control variable is not incremented or decremented in a for loop?
Correct Answer: B) The loop will become an infinite loop
7. Which loop guarantees that the loop body will execute at least once, even if the condition is false initially?
Correct Answer: C) Do-while loop
8. Which of the following loops is best suited for a situation where the number of iterations is not known in advance?
Correct Answer: B) While loop
9. Which statement is true about nested loops?
Correct Answer: B) Any number of loops can be nested within another loop
10. What happens if the condition of a for loop is omitted?
Correct Answer: B) The loop will execute infinitely
11. Which loop type is used when a condition needs to be tested after executing the loop body?
Correct Answer: C) Do-while loop
12. What will happen in the following code?
int i = 10;
while(i > 5)
{
printf("%d", i);
}
Correct Answer: A) The loop will execute infinitely
13. What is the default step value in a for loop if it is not explicitly specified?
Correct Answer: B) 1
14. Which of the following conditions can result in an infinite loop?
Correct Answer: D) All of the above
15. What should be established at the outset of a loop in order to prevent infinite execution?
Correct Answer: C) Initialization, condition, and step value
16. What is the primary difference between a while loop and a for loop?
Correct Answer: C) A for loop is typically used when the number of iterations is known
17. What is the condition for a loop to stop executing?
Correct Answer: C) The loop condition becomes false
18. What is a "nested loop" in programming?
Correct Answer: B) A loop placed inside another loop
19. Which of the following is an example of a scenario where nested loops are typically used?
Correct Answer: C) Working with two-dimensional data structures like matrices
20. In the following structure of a nested loop, which loop runs first?
for (initialization; condition; increment/decrement) {
// Outer loop code
for (initialization; condition; increment/decrement) {
// Inner loop code
}
}
Correct Answer: C) Outer loop
21. What does the following nested loop in C print?
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 2; j++) {
printf("%d %d\n", i, j);
}
}
Correct Answer: A) Pairs of numbers from 1 to 2
22. In the example of printing a multiplication table, what is printed by the inner loop?
Correct Answer: B) Columns of the table
23. What is the purpose of the printf("\n"); statement in the multiplication table example?
Correct Answer: C) It moves to the next line after printing each row
24. How many times will the inner loop execute if the outer loop runs 10 times and the inner loop also runs 10 times?
Correct Answer: B) 100
25. In the multiplication table example, what does the expression i * j represent?
Correct Answer: C) The product of i and j
26. Which of the following is NOT a correct description of the use of nested loops?
Correct Answer: B) They always result in infinite loops
27. What is the output of the following code snippet?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 2; j++) {
printf("%d ", i);
}
}
Correct Answer: A) 1 1 2 2 3 3